package de.kiltz.foo.mvc;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import de.kiltz.foo.domain.Foo;
import de.kiltz.foo.service.FooService;

public class DetailController  implements Controller
{

	/** Logger for this class and subclasses */
    protected final Log logger = LogFactory.getLog(getClass());

    private FooService fooService;


	public void setFooService(FooService fooService) {
		this.fooService = fooService;
	}

	@Override
	public ModelAndView handleRequest(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		Map<String, Object> daten = new HashMap<String, Object>();
		Integer id = Integer.parseInt(request.getParameter("id"));
		Foo f = fooService.get(id);
        daten.put("foo", f);
        daten.put("info", "Suche Foo mit id "+request.getParameter("id"));
		return new ModelAndView("detail", "daten", daten);
	}



}
